package com.gupaoedu.vip.demo.mvc.action;

import com.gupaoedu.vip.demo.service.IDemoService;
import com.gupaoedu.vip.spring.annotation.GPAutowired;
import com.gupaoedu.vip.spring.annotation.GPController;
import com.gupaoedu.vip.spring.annotation.GPRequestMapping;
import com.gupaoedu.vip.spring.annotation.GPRequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author JLL
 * @Date 2018/11/6/0006 下午 10:40
 */

@GPController
@GPRequestMapping("/demo")
public class DemoAction {

    @GPAutowired
    private IDemoService demoService;

    @GPRequestMapping("/query")
    public void query(HttpServletRequest req, HttpServletResponse resp,
                      @GPRequestParam("name") String name){
        String result1 = demoService.getName(name);
        System.out.println(result1);
		try {
			resp.getWriter().write(result1 +"   " );
		} catch (IOException e) {
			e.printStackTrace();
		}
    }

    @GPRequestMapping("/edit.json")
    public void edit(HttpServletRequest req,HttpServletResponse resp,Integer id){

    }

    @GPRequestMapping("/add")
    public void add(@GPRequestParam("a") Integer a, @GPRequestParam("b") Integer b,
                    HttpServletRequest req, HttpServletResponse resp){
        try {
            resp.getWriter().write(a + "+" + b + "=" + (a + b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GPRequestMapping("/sub")
    public void add(HttpServletRequest req, HttpServletResponse resp,
                    @GPRequestParam("a") Double a, @GPRequestParam("b") Double b){
        try {
            resp.getWriter().write(a + "-" + b + "=" + (a - b));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @GPRequestMapping("/remove")
    public String  remove(@GPRequestParam("id") Integer id){
        return "" + id;
    }



    /*public static void main(String[] args) {
        //二维数组测试
        //定义二维数组
        int[][]  arr = {{5,7,9},{12,14,16,18},{23,25,36,47},{22,54,65,15},{22,34},{11,55,89}};
        //一维数组是{}的东西。。
        System.out.println(arr.length);
        for(int i=0;i<arr.length;i++) {
            for(int j=0;j<arr[i].length;j++)//利用嵌套for循环来遍历二维数组
            {
                System.out.print(arr[i][j] + " ");
            }
        }
    }*/




}
